package com.jrtc.backend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jrtc.base.entity.bo.Doctordisease;
import com.jrtc.base.config.dto.ResultDTO;
import com.jrtc.base.config.dto.ResultDTOBuilder;
import com.jrtc.service.DoctordiseaseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 医生疾病关联表(Doctordisease)表控制层
 *
 * @author makejava
 * @since 2022-03-21 17:19:03
 */
@RestController
@RequestMapping("doctordisease")
public class DoctordiseaseController {
    /**
     * 服务对象
     */
    @Resource
    private DoctordiseaseService doctordiseaseService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Doctordisease selectOne(Integer id) {
        return this.doctordiseaseService.queryById(id);
    }
    
    @RequestMapping("getDoctordiseaseList")
    public ResultDTO getDoctordiseaseList(@RequestBody Doctordisease doctordisease)
    {
        IPage<Doctordisease> ipage = doctordiseaseService.queryDoctordiseaseList(doctordisease);
        return ResultDTOBuilder.success(ipage);
    }

    @RequestMapping("insertDoctordisease")
    public ResultDTO insertDoctordisease(@RequestBody Doctordisease doctordisease)
    {
        Doctordisease tmpDoctordisease = doctordiseaseService.insert(doctordisease);
        if (tmpDoctordisease != null)
        {
           return ResultDTOBuilder.success("添加成功！");
        }
        return ResultDTOBuilder.failureMsg("添加失败！");
    }

    @RequestMapping("getDoctordiseaseById")
    public ResultDTO getDoctordiseaseById(@RequestBody Map<String, Integer> map)
    {
        int doctordiseaseId = map.get("doctordiseaseId");
        Doctordisease doctordisease = doctordiseaseService.queryById(doctordiseaseId);
        if (doctordisease==null)
        {
            return ResultDTOBuilder.failureMsg("信息有误！");
        }
        return ResultDTOBuilder.success(doctordisease);
    }

    @RequestMapping("updateDoctordisease")
    public ResultDTO updateDoctordisease(@RequestBody Doctordisease doctordisease)
    {
        if (doctordisease==null)
        {
            return ResultDTOBuilder.failureMsg("信息有误！");
        }
        if (doctordiseaseService.update(doctordisease)!=null)
        {
            return ResultDTOBuilder.success("修改信息成功！");
        }
        return ResultDTOBuilder.failureMsg("修改信息失败！");
    }
    
    @RequestMapping("deleteDoctordisease")
    public ResultDTO deleteDoctordisease(@RequestBody Map<String,Integer> map)
    {
        int doctordiseaseId = map.get("doctordiseaseId");
        if (doctordiseaseService.deleteById(doctordiseaseId))
        {
            return ResultDTOBuilder.success("删除成功！");
        }
        return ResultDTOBuilder.failureMsg("删除失败！");
    }
}